package com.beibeilian.guanzhu;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.beibeilian.android.app.R;
import com.beibeilian.util.HttpConstantUtil;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by JX on 2017/9/11.
 */

public class LiwuAdapter extends BaseAdapter {

    private Context mContext;

    private List<GiftBean> data;

    public LiwuAdapter(Context mContext, List<GiftBean> data) {
        this.mContext = mContext;
        this.data = new ArrayList<>();
        if (data != null) {
            this.data.addAll(data);
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_liwu, null);
            viewHolder.iv_iamge = (ImageView) convertView.findViewById(R.id.iv_image);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            // init
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        GiftBean bean = data.get(position);
        Glide.with(mContext).load(HttpConstantUtil.IMAGE_URL + bean.getGiftPhoto()).into(viewHolder.iv_iamge);
        viewHolder.tv_name.setText(bean.getGiftName());
        viewHolder.tv_price.setText(bean.getPrice());

        return convertView;
    }

    class ViewHolder {
        ImageView iv_iamge;
        TextView tv_price;
        TextView tv_name;
    }
}
